

using Unity.VisualScripting;
using UnityEngine;

public static class UTransform
{
    public static void LookTarget(this Transform t,Transform target)
    {
        if(target == null)
            return;
        
        //先拉到同一个水平 再转向
        Vector3 targetPosition = new Vector3(target.position.x,target.position.y,target.position.z);
        t.LookAt(targetPosition);

        //
    }

    public static void LookTarget(this Transform t, Vector3 target)
    {
        if (target == null)
            return;

        //先拉到同一个水平 再转向
        Vector3 targetPosition = new Vector3(target.x, target.y, target.z);
        t.LookAt(targetPosition);

        //
    }

    //圆内 固定角度 找一点
    public static Vector3 GetOffsetPosition(this Transform t,float radius,float angle)
    {
        if(radius ==0 && angle == 0)
        {
            return t.transform.position;    
        }
        float x = Mathf.Sin(angle * Mathf.PI/180) * radius;
        float z = Mathf.Cos(angle * Mathf.PI / 180) * radius;
        Vector3 res = t.position + t.rotation * new Vector3(x, 0, z); //这个东西长得好像极坐标
        return res;
    }
}